package com.getpebble.android.onboarding.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.Analytics.MobileAppBehavior;
import com.getpebble.android.common.framework.fragment.PblBaseFragment;
import com.getpebble.android.onboarding.activity.OnboardingActivity;
import com.getpebble.android.util.HttpUtils;

public class AppCheckUpdateFragment extends PblBaseFragment {
    public int getLayoutId() {
        return R.layout.fragment_check_app_update;
    }

    public void init(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        MobileAppBehavior.logScreenOpened("OnboardingMigrationAppInstall");
        ((Button) container.findViewById(R.id.onboarding_check_now_btn)).setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                MobileAppBehavior.logButtonTapped("startUpdate", "OnboardingMigrationAppInstall");
                Activity activity = AppCheckUpdateFragment.this.getActivity();
                if (activity != null && (activity instanceof OnboardingActivity)) {
                    OnboardingActivity onboardingActivity = (OnboardingActivity) activity;
                    if (HttpUtils.hasInternetConnection(activity.getApplicationContext())) {
                        onboardingActivity.switchScreenFragment(new CompatibleAppsWebViewFragment());
                    } else {
                        onboardingActivity.switchToNoConnectivityFragment();
                    }
                }
            }
        });
    }
}
